package com.weiyi.mashangzhu.http;

import com.weiyi.mashangzhu.Roomer.Bean.DataInfo;
import com.weiyi.mashangzhu.http.util.ProgressSubscriber;
import com.weiyi.mashangzhu.http.util.RetrofitUtil;

import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class HttpUtil {

    private static HttpUtil httpUtil = new HttpUtil();
    private ApiService apiService;

    private HttpUtil() {
        apiService = RetrofitUtil.getInstance().getApiService();
    }

    public static HttpUtil getInstance() {
        return httpUtil;
    }

    private <T> void toSubscribe(Subscriber<T> subscriber, Observable<T> observable) {
        observable.subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    /**
     * 以下自定义获取服务器数据
     */

    public void getDataList(ProgressSubscriber<DataInfo> subscriber, int page, int rows) {
        toSubscribe(subscriber, apiService.getData(page, rows));
    }


}
